//
//  SSMainViewController.swift
//  SSSina
//
//  Created by ss on 2017/6/28.
//  Copyright © 2017年 ss. All rights reserved.
//

import UIKit
class SSMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //自定义tabBar 
        let tabBar = SSTabBar()
        
        //设置代理
        tabBar.ssDelegate = self 
         //02 闭包实例化
        tabBar.closure = {
            //04 回调
            print("监听按钮,点击回调")
        }
        
        //使用KVC 完成制度属性的赋值
        setValue(tabBar, forKey: "tabBar")
        
        
        
        addChildViewController(childController: SSHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: SSMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: SSDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: SSProfielViewController(), title: "我", imageName: "tabbar_message_center")
        
    }
    
    func addChildViewController(childController: UIViewController,title: String,imageName: String) {
        
    
        //设置title
        childController.navigationItem.title = title
        childController.tabBarItem.title = title
        
        //设置选中字的颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        
        //设置image
        childController.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        //选中
        //.withRenderingMode(UIImageRenderingMode.alwaysOriginal) 图片渲染
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        //导航控制器
        let nav = UINavigationController(rootViewController: childController)
        
        //添加子控制器
        addChildViewController(nav)
        
    }

}

extension SSMainViewController:SSTabBarDelegate{
    func composeButtonSelect(){
        print("代理方式,按钮点击")
        SSComposeView.show(target: self)
    }
}


